package com.test.thread.virtualthread;

import jdk.internal.vm.Continuation;
import jdk.internal.vm.ContinuationScope;

import java.util.concurrent.atomic.AtomicInteger;

public class VirtualThread {
    public static final ContinuationScope SCOPE = new ContinuationScope("VirtualThread");
    private static final AtomicInteger COUNTER = new AtomicInteger();

    private final Continuation cont;

    private final int id;

    public VirtualThread(Runnable target) {
        cont = new Continuation(SCOPE, target);
        id = COUNTER.incrementAndGet();
    }

    public void run() {
        System.out.println("VirtualThread " + id + " is running on " + Thread.currentThread());
        cont.run();
    }
}
